package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.db.DaoSingleton;
import com.lanou.sfu.songforu.entity.ArtistDetailSongEntity;

import java.util.List;

/**
 * Created by dllo on 15/10/27.
 */
public class ArtistDetailSongListViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<ArtistDetailSongEntity.SonglistEntity> datas;
    private DaoSingleton daoSingleton;

    public void addData(Context context, List<ArtistDetailSongEntity.SonglistEntity> lists){
        daoSingleton = DaoSingleton.getInstance();
        mContext = context;
        datas = lists;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (datas != null && datas.size() > 0) {
            return datas.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {

        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.artist_detail_song_listview_item, null);
            holder = new ViewHolder();
            holder.authersNames = (TextView) convertView.findViewById(R.id.artist_detail_song_authersNames);
            holder.songsNames = (TextView) convertView.findViewById(R.id.artist_detail_songName);
            holder.songDow = (ImageButton) convertView.findViewById(R.id.artist_detail_song_more);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final ArtistDetailSongEntity.SonglistEntity artistDetailSongEntity = (ArtistDetailSongEntity.SonglistEntity) getItem(position);
        if (artistDetailSongEntity != null) {
            holder.authersNames.setText(artistDetailSongEntity.getAuthor());
            holder.songsNames.setText(artistDetailSongEntity.getTitle());
        }

        holder.songDow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        return convertView;
    }

    public class ViewHolder {
        private ImageButton songDow;
        private TextView songsNames, authersNames;
    }

}
